/*
 * TSystem.c
 *
 * Created: 10.02.2013 12:08:47
 *  Author: victor
 */
/*This module is the time base for the scheduler*/

/* Module's includes */
#include <TSystem.h>
#include <Basetypes.h>
#include <OutputHdl.h>
#include <SerialHdl.h>
#include <Processing.h>
#include <TimerDrv.h>
//temp
#include <CommonDefinitions.h>

/* Module's definitions */
#define TSYSTEM_C_TEN_MULTIPLIER_U8   (u8)10

void TSystem_1msTask();
void TSystem_10msTask();
void TSystem_100msTask();
void TSystem_1000msTask();

/* Module's function definitions */
void TSystem_1msTask ( void )
{
	static unsigned char tmp_10msCounter_u8 = 0;
	tmp_10msCounter_u8++;
	
	/* Functions to be called each ms */
	OutputHdl_PBCheck();
	
	/* Evaluate if 10 ms have been elapsed */
	if ( TSYSTEM_C_TEN_MULTIPLIER_U8 == tmp_10msCounter_u8 )
	{
		TSystem_10msTask();
		tmp_10msCounter_u8 = 0;
	}
}

void TSystem_10msTask ( void )
{
	static unsigned char tmp_100msCounter_u8 = 0;
	tmp_100msCounter_u8++;
	
	if ( TSYSTEM_C_TEN_MULTIPLIER_U8 == tmp_100msCounter_u8 )
	{
		TSystem_100msTask();
		tmp_100msCounter_u8 = 0;
	}
}

void TSystem_100msTask ( void )
{
	static unsigned char tmp_1000msCounter_u8 = 0;
	tmp_1000msCounter_u8++;
	
	if ( TSYSTEM_C_TEN_MULTIPLIER_U8 == tmp_1000msCounter_u8 )
	{
		TSystem_1000msTask();
		tmp_1000msCounter_u8 = 0;
	}
}

void TSystem_1000msTask ( void )
{
	/*Transmit the song timing each second*/
	Processing_CyclicMessages();
}